package com.hsurosy.domain.strategy.service.rule.chain.impl;

import com.hsurosy.domain.strategy.service.armory.IStrategyDispatch;
import com.hsurosy.domain.strategy.service.rule.chain.AbstractLogicChain;
import com.hsurosy.domain.strategy.service.rule.chain.factory.DefaultChainFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author Hsu琛君珩
 * @Date 2024-10-19 1:17
 * @Description 兜底责任链节点的实现类
 * @Version: v1.0.0
 */
@Slf4j
@Component("rule_default")
public class DefaultLogicChain extends AbstractLogicChain {

    @Resource
    protected IStrategyDispatch strategyDispatch; // 策略分发接口

    /**
     * 默认的责任链逻辑处理方法
     *
     * @param userId 用户ID，用于标识抽奖用户
     * @param strategyId 抽奖策略ID，用于标识当前的抽奖策略
     * @return 返回随机抽取的奖品ID
     */
    @Override
    public DefaultChainFactory.StrategyAwardVO logic(String userId, Long strategyId) {
        // 调用策略调度器获取一个随机的奖品ID
        Integer awardId = strategyDispatch.getRandomAwardId(strategyId);
        // 记录日志，说明当前使用的是默认处理逻辑
        log.info("抽奖责任链-默认处理 userId: {} strategyId: {} ruleModel: {} awardId: {}", userId, strategyId, ruleModel(), awardId);
        // 返回随机的奖品ID
        return DefaultChainFactory.StrategyAwardVO.builder()
                .awardId(awardId)
                .logicModel(ruleModel())
                .build();
    }

    @Override
    protected String ruleModel() {
        return DefaultChainFactory.LogicModel.RULE_DEFAULT.getCode(); // 当前是兜底处理的节点
    }

}
